package com.zw.mes.module.shipments.controller;


import com.zw.mes.base.BaseController;
import com.zw.mes.common.JsonResult;
import com.zw.mes.entity.shipments.InstDispatchingDetail;
import com.zw.mes.entity.shipments.InstDispatchingFile;
import com.zw.mes.entity.shipments.InstDispatchingList;
import com.zw.mes.entity.shipments.InstShipmentsPlanSheet;
import com.zw.mes.module.cost.service.DictCommonService;
import com.zw.mes.module.shipments.service.InstDispatchingCreateService;
import com.zw.mes.module.shipments.service.InstShipmentsPlanService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.xml.crypto.Data;

import java.text.ParseException;
import java.util.List;

import static com.zw.mes.constant.Constant.GROUP_SPECTYPE;


/**
 * @Description: 创建安装派工单
 * <p>
 * 权限：
 * @Author: liqingyu
 * @Date: 2020/11/10 08:58
 */
@Controller
@RequestMapping("/create/dispatching")
@SuppressWarnings("all")
public class InstDispatchingCreateController extends BaseController {


    @Autowired
    private DictCommonService dictCommonService;
    @Autowired
    private InstDispatchingCreateService instDispatchingCreateService;


    @GetMapping
//    @RequiresPermissions({"tec:proDetail:view"})
    public String page(Model model) {
        model.addAttribute("specialId", dictCommonService.findDictByGroupName(GROUP_SPECTYPE));
        return "shipments/InstDispatchingCreate/page";
    }

    /**
     *
     * @param model
     * @return
     */
    @GetMapping("/debuggingPage")
    public String debuggingPage(Model model) {
        return "shipments/instDebugging/debuggingPage";
    }
    /**
     * 增加发货计划主单
     *
     * @param instShipmentsPlanSheet
     * @return
     */
    @ResponseBody
    @PostMapping("/addDispatching")
//    @RequiresPermissions({"tec:proProduc:edit"})
    public JsonResult addProduction(InstDispatchingList instDispatchingList, String[] special, String[] installPrincipal, String[] installTime, Integer[] isDebugging, String[] installRemark) throws ParseException {
       int i = instDispatchingCreateService.saveAll(instDispatchingList,special,installPrincipal,installTime,isDebugging,installRemark);
        return jsonResult(1);
    }
    /**
     * 调试反馈集合
     *
     * @param dsnGant
     * @return
     */
    @ResponseBody
    @PostMapping("/debuggingList")
    public JsonResult debuggingList(InstDispatchingList instDispatchingList) {
        startPage();
        List<InstDispatchingList> list = instDispatchingCreateService.findinstDispatchingQuery(instDispatchingList);
        return jsonResult(list);
    }
    /**
     * 调试反馈明细集合
     *
     * @param dsnGant
     * @return
     */
    @ResponseBody
    @PostMapping("/debuggingDetail")
    public JsonResult debuggingDetail(InstDispatchingDetail instDispatchingDetail) {
        startPage();
        List<InstDispatchingDetail> list = instDispatchingCreateService.findinstDispatchingDetailQuery(instDispatchingDetail);
        return jsonResult(list);
    }
    /**
     * 增加发货计划主单
     *
     * @param instShipmentsPlanSheet
     * @return
     */
    @ResponseBody
    @PostMapping("/debuggingDetailSave")
    public JsonResult addProduction(InstDispatchingDetail instDispatchingDetail) {
        instDispatchingCreateService.saveInstDispatchingDetail(instDispatchingDetail);
        return jsonResult(1);
    }
    /**
     * 调试文件列表
     *
     * @param dsnGant
     * @return
     */
    @ResponseBody
    @PostMapping("/debuggingFile")
    public JsonResult debuggingFile(InstDispatchingFile instDispatchingFile) {
        startPage();
        //调试
        instDispatchingFile.setType(2);
        List<InstDispatchingFile> list = instDispatchingCreateService.findinstDispatchingFileQuery(instDispatchingFile);
        return jsonResult(list);
    }
    /**
     * 导入
     *
     * @param file 导入文件
     * @return JsonResult
     */
    @ResponseBody
    @PostMapping("/uploadFileExp")
    public JsonResult uploadFileExp(InstDispatchingFile instDispatchingFile,@RequestParam("file") MultipartFile file) {
        instDispatchingFile.setType(2);
        instDispatchingCreateService.uploadFileExp(instDispatchingFile, file);
        return success();
    }
    /**
     * 修改说明文件
     */
    @ResponseBody
    @PostMapping("/updExp")
    public JsonResult updDubuggingExp(InstDispatchingFile instDispatchingFile) {
        return jsonResult(instDispatchingCreateService.updExplainById(instDispatchingFile));
    }
    /**
     * 删除附件
     */
    @ResponseBody
    @PostMapping("/delExp")
    public JsonResult delExp(InstDispatchingFile instDispatchingFile) {
        return jsonResult(instDispatchingCreateService.delExp(instDispatchingFile));
    }
}
